#pragma once
#include <map>
#include <vector>
#include <mutex>
using namespace std;

// Define a class derived from CWinThread
class CAsynCom {
public:
    CSCOM* m_com;
    CEvent m_txEvent;
    BOOL bloop;
    int sel_comp;
    int ctrl_key;
    ULONGLONG ctrl_tick;
    int m_comp;
    int m_baud;
    std::string logfile;
    FIFO* txqueue;

    std::string strport;
    int net_port;
    std::string net_ip;

protected:
    HANDLE hThread;
    DWORD  threadId;
    char* strlog;
    WSADATA wsaData;
    SOCKET sockfd;
    HANDLE hThreadSockt;
    DWORD  threadSocktId;
    std::mutex uartMutex;
public:
    CAsynCom(int comp = -1, int baud = -1);
    virtual ~CAsynCom();
    int Start(int comp = -1, int baud = -1);
    int showLogs(char* slog, int len);
    void rxProcEntry();
    int keyboardProcEntry();
    int findwords();
    int popmenu();
    int connNetCom();
    int closeNetCom();
    int socketRxProc();
};

void show_devices(bool breshow = TRUE, vector<int> *comp_list=NULL);
int choos_comp(bool reshow);

int server_entry(int argc, const char* cargv[]);